<!DOCTYPE html>
<html>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
	    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
	    <title>Hello APP</title>
	    <link rel="stylesheet" type="text/css" href="../../../css/index.css" />
	</head>
	<style type="text/css">
		.warp{width: 100%;}
		.tishi-box{width: 100%;height: auto;padding: 15px;box-sizing: border-box;background: #FF9502;font-size: 15px;color: #ffffff;display: none;}

		.info-box{width: 100%;margin-bottom: 10px;}
		.info-box .info-one{align-items: center;padding:15px;background: #FFFFFF;box-sizing: border-box;}
		.info-box .info-one .text{font-size: 15px;}
		.info-box .info-one .cont{font-size: 15px;color: #666666;padding-left: 20px;text-align: right;}
		.info-box .info-one .cont.r{padding-right: 6px;box-sizing: border-box;}
		.sku-box{background: #ffffff;padding: 0 15px;box-sizing: border-box;}
		.sku-box .t{font-size: 15px;padding-top: 10px;}
		.sku-box .sku-list .sku-one{padding: 10px 0;box-sizing: border-box;}
		.sku-box .sku-list .sku-one .info{font-size: 15px;color: #666666;padding-bottom: 10px;align-items: center;}
		.sku-box .sku-list .sku-one .info .i-box{background: #f8f8f8;line-height: 32px;width: 100px;padding: 0 10px;box-sizing: border-box;}
		.sku-box .sku-list .sku-one .info .i-box input{width:100%;box-sizing: border-box;}
		.sku-box .sku-list .sku-one .info span{padding: 0 20px;box-sizing: border-box;display: block;}

		.fixed_btn{position: fixed;bottom: 0;left: 0;height: 60px;background: #ffffff;z-index: 999;right: 0;}
		.fixed_btn .btn-box3{width: 100%;height: 100%;padding: 8px 15px;box-sizing: border-box;line-height: 44px;}
		.fixed_btn .btn-box3 .btn1{width: 120px;border-radius: 30px;text-align: center;font-size: 15px;background: #ffffff;margin-right: 12px;color: #FF9502;
		border: 1px solid #FF9502;box-sizing: border-box;}
		.fixed_btn .btn-box3 .btn3{border-radius: 30px;text-align: center;font-size: 15px;background: #FF9502;color: #ffffff;}

		.shangjia{padding-left: 24px;background: url(../../../image/main2/sel_icon0.png) no-repeat left center;background-size: 16px;margin-left: 20px;}
		.shangjia.on{background: url(../../../image/main2/sel_icon1.png) no-repeat left center;background-size: 16px;}
	</style>
	<body>
		<div id="vue" class="warp">
			<div class="tishi-box" :style="{ display:(Pdata.forced_down == 1 ? '':'none')}" v-text="Pdata.forced_down_msg"></div>
			<div class="info-box">
	        	<div class="info-one flex border-bottom">
	        		<div class="text">商品标题</div>
					<div class="cont flex1" v-text="Pdata.title"></div>
	        	</div>
				<div class="info-one flex border-bottom">
	        		<div class="text">副标题</div>
					<div class="cont flex1" v-text="Pdata.tit"></div>
	        	</div>
				<div class="info-one flex border-bottom" v-if="stype == 'shop'">
	        		<div class="text">商品分类</div>
					<div class="cont flex1" v-text="Pdata.cateid_str"></div>
	        	</div>
				<div class="info-one flex">
	        		<div class="text">所属商家</div>
					<div class="cont flex1" v-text="Pdata.pinpai_name"></div>
	        	</div>
	        </div>
			<div class="info-box">
				<div class="info-one flex border-bottom" v-if="Pdata.isguige == 1">
	        		<div class="text">商品编码</div>
					<div class="cont flex1" v-text="Pdata.gdata[0].code"></div>
	        	</div>
				<div class="info-one flex border-bottom">
	        		<div class="text flex1">上架状态</div>
					<span class="shangjia" data-sta='1' tapmode onclick="tabsta(this)">上架</span>
					<span class="shangjia on" data-sta='0' tapmode onclick="tabsta(this)">待上架</span>
	        	</div>
				<div class="info-one flex border-bottom">
	        		<div class="text">市场参考价</div>
					<input class="cont flex1 r" type="number" oninput="if(value.length>8)value=value.slice(0,8)" id="scprice" :value="Pdata.scprice" placeholder="请输入市场参考价">元
	        	</div>
				<div class="info-one flex border-bottom" v-if="Pdata.isguige == 1">
	        		<div class="text">商品售价</div>
					<input class="cont flex1 r" type="number" oninput="if(value.length>8)value=value.slice(0,8)" id="price" :value="Pdata.gdata[0].price" placeholder="请输入商品售价">元
	        	</div>
				<div class="info-one flex border-bottom" v-if="stype == 'jifen' && Pdata.gdata && Pdata.isguige == 1">
	        		<div class="text">所需积分</div>
					<input class="cont flex1 r" type="number" oninput="if(value.length>8)value=value.slice(0,8)" id="unscore" :value="Pdata.gdata[0].unscore" placeholder="请输入所需积分">积分
	        	</div>
				<div class="info-one flex border-bottom" v-if="Pdata.isguige == 1">
	        		<div class="text">库存</div>
					<input class="cont flex1 r" type="number" oninput="if(value.length>8)value=value.slice(0,8)" id="num" :value="Pdata.gdata[0].num" placeholder="请输入库存">件
	        	</div>
				<div class="info-one flex" v-if="Pdata.isguige == 1">
	        		<div class="text">重量</div>
					<input class="cont flex1 r" type="number" oninput="if(value.length>8)value=value.slice(0,8)" id="kg" :value="Pdata.gdata[0].kg" placeholder="请输入重量">kg
	        	</div>
				<div class="sku-box" v-if="Pdata.isguige == 2">
					<div class="t">SKU类型</div>
					<div class="sku-list">
						<div class="sku-one border-bottom" v-for="(item,key) in Pdata.gdata" :data-n="item.n">
							<div class="info">商品编码：<i v-text="item.code"></i></div>
							<div class="info" v-text="item.ggstr"></div>
							<div class="info flex">库存：<div class="i-box flex"><input class="flex1 s_num" type="number" oninput="if(value.length>8)value=value.slice(0,8)" :value="item.num"><i>件</i></div></div>
							<div class="info flex">重量：<div class="i-box flex"><input class="flex1 s_kg" type="number" oninput="if(value.length>8)value=value.slice(0,8)" :value="item.kg"><i>kg</i></div></div>
							<div class="info flex">价格：
								<div class="i-box flex"><input class="flex1 s_price" type="number" oninput="if(value.length>8)value=value.slice(0,8)" :value="item.price"><i>元</i></div>
								<span v-if="stype == 'jifen' && Pdata.gdata">+</span>
								<div v-if="stype == 'jifen' && Pdata.gdata" class="i-box flex">
									<input class="flex1 s_unscore" type="number" maxlength="8" :value="item.unscore"><i>积分</i>
								</div>
							</div>
						</div>
					</div>
				</div>
	        </div>

			<div style="width:100%;height:150px;"></div>
			<!--底部按钮-->
			<div class="fixed_btn" id="app-footer">
				<div class="btn-box3 flex">
					<div class="btn1" tapmode onclick="api.closeWin()">取消</div>
					<div class="btn3 flex1" tapmode onclick="upData()">确定提交</div>
				</div>
			</div>

		</div>
	</body>
</html>
<script type="text/javascript" src="../../../script/base.min.js" id="loadjs" data-js="L/swiper.min,L/lazyload,L/h-tool"></script>
<script type="text/javascript">

	define(function (require, exports, module) {

		lanYun.setFooter('app-footer');
		var sdata = {};
		var stype = pageParam.type;
		sdata.id = pageParam.id;
		sdata.isjia = 0;

		var url = {
            "shop":{
                "show":'store/Goods/show',
                "edit":'store/Goods/edit_gdata',
            },
            "jifen":{
                "show":'store/ScoreGoods/show',
                "edit":'store/ScoreGoods/edit_gdata',
            },
        }

		_page.getData = function(loading) {
			lanYun.getVueData({url:url[stype].show,get:{id:pageParam.id},cache:0,loading:loading},function(ret) {
				//console.log(JSON.stringify(ret))
				if(ret.errcode != 0){
					lanYun.toast(ret.mag);
				}
			});
		};

		lanYun.newVue('#vue',{
			stype:stype
		},function() {
			_page.getData(2);
		});

		// 提交修改信息
		upData = function (){
			var sta = lanYun.vue.Pdata.isguige;
			sdata.updtime = lanYun.vue.Pdata.updtime;
			sdata.scprice = $('#scprice').val();
			write_data();
			if(!sdata.scprice) {
				lanYun.toast('请输入市场参考价');
				return;
			}
			$.each(sdata.gdata,function (i,n) {
				$.each(n,function(a,b) {
					if(b == ""){
						lanYun.toast('请完善规格信息');
						return;
					}
				})
			})
			lanYun.post(url[stype].edit,sdata,function (ret) {
				lanYun.toast(ret.msg);
				//console.log(JSON.stringify(ret));
				if(ret.errcode == 0){
					api.execScript({ name:pageParam.winName, frameName:pageParam.frameName, script:'intGetData();'});
					setTimeout(function(){
						api.closeWin();
					},800)
				}else if(ret.errcode == 2){
					lanYun.alert({fname:'diaLogBox1',title:'提示', button:['确定'],content: ret.msg },function(ret){
                        _page.getData(2);
        	        });
				}
			},2)
		}

		//获取数据
		write_data = function (){
			var sta = lanYun.vue.Pdata.isguige;
			var type = lanYun.vue.stype;
			sdata.gdata = [];
			if(sta == 2){
				$('.sku-one').each(function (k,v){
					var cont = {};
					cont.n = v.dataset.n;
					cont.price = $(v).find('.s_price').val();
					cont.num = $(v).find('.s_num').val();
					cont.kg = $(v).find('.s_kg').val();
					if(type == 'jifen'){
						cont.unscore = $(v).find('.s_unscore').val();
					}
					sdata.gdata.push(cont);
				});
			}else {
				var cont = {};
				cont.n = '0';
				cont.price = $('#price').val();
				cont.num = $('#num').val();
				cont.kg = $('#kg').val();
				if(type == 'jifen'){
					cont.unscore = $('#unscore').val();
				}
				sdata.gdata.push(cont);
			}
		}

		//切换上架状态
		tabsta = function (tis) {
			var dst = tis.dataset;
			$('.shangjia').removeClass('on');
			$(tis).addClass('on');
			sdata.isjia = dst.sta;
		}

	});
</script>
